package com.google.common.base;

import java.io.Serializable;
import javax.annotation.Nullable;

public abstract class Equivalence<T> {

    static final class Equals extends Equivalence<Object> implements Serializable {
        static final Equals INSTANCE = new Equals();

        Equals() {
        }

        protected boolean doEquivalent(Object a, Object b) {
            return a.equals(b);
        }
    }

    protected abstract boolean doEquivalent(T t, T t2);

    protected Equivalence() {
    }

    public final boolean equivalent(@Nullable T a, @Nullable T b) {
        if (a == b) {
            return true;
        }
        if (a == null || b == null) {
            return false;
        }
        return doEquivalent(a, b);
    }

    public static Equivalence<Object> equals() {
        return Equals.INSTANCE;
    }
}
